<?php
class Application_Model_StoreLocation extends Application_Model_DomainObject{
	
	protected $_id;             //库位表的ID
	
	protected $_userId;        //用户ID
	
	protected $_locationNo;     //仓库号
        
        protected $_status;       //状态
        
        protected $_library;      //仓库列号
        
        protected $_datecreated;    //开库位时间
        
        public function getuserinfo(){
            if($this->_userId)
            {
                return Application_Model_User::load($this->_userId);
            }
        }
        
        public static function getSearch($name){
            $uwhere['( nikename like '] = "%".$name."%";
            $uwhere[ ' or storeno like '] = "%".$name."%";
            $uwhere[" ) and "] = 1;
            $res = Application_Model_User::getDao()->queryAll($uwhere);
            $or = "";
            $where = array();
            foreach($res as $val){
                $where[$or.' userId ='] = $val->id;
                $or = "or";
            }
            $where[$or.' locationNo like '] = "%".$name."%";
            return Application_Model_StoreLocation::getDao()->queryAll($where);
        }
        
        public static function getAll($name){
            $where=array();
            if($name != null){
                $where=array('library'=>$name);
            }
            return Application_Model_StoreLocation::getDao()->queryAll($where);
        }
        
        public static function getUserAll($id)
        {
            return self::getDao()->queryAll(array("userId"=>$id));
        }
        
        public static function getRemoveLocation($locationNo)
        {
            $result = self::getDao()->queryOne(array("locationNo"=>$locationNo));
            if($result){
                $result->userId = null;
                $result->status = 0;
                $result->save();
                return 1;
            }else{
                return 0;
            }
        }
        public static function byUseridRemoveLocation($userId)
        {
            $result = self::getDao()->queryAll(array("userId"=>$userId));
            foreach ($result as $value) {
                $value->userId = null;
                $value->status = 0;
                $value->save();
            }
            return 1;
        }

        public static function getLocationInfo($locationNo)
        {
            return self::getDao()->queryOne(array("locationNo"=>$locationNo));
        }
        
        public static function getLocation($userId)
        {
            $res = self::getDao()->queryAll(array("userId"=>$userId));
            $storeNo = array();
            foreach($res as $val){
                $storeNo[] = $val->locationNo;
            }
            return $storeNo;
        }
        
}